﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetMQ;
using NetMQ.Sockets;
using DataTransFrame;

namespace DataTramsmittingServer
{
    public class SubClient
    {

        #region 归集端
        public void ShowText(object obj)
        {
            try
            {
                using (var sub = new SubscriberSocket())
                {
                    sub.Options.ReceiveHighWatermark = 1000;
                    sub.Connect("tcp://localhost:38401");
                    sub.Subscribe(Encoding.UTF8.GetBytes($"{obj}"));
                    while (true)
                    {
                        try
                        {
                            string idcard = sub.ReceiveFrameString();
                            TranServerToTerminal tvalues = new Common().GetProtobufObjectFromBytes<DataTransFrame.TranServerToTerminal>(sub.ReceiveFrameBytes());
                            Console.WriteLine($"IDCARD:{idcard}\r\nTOPIC:{tvalues.TOPIC}\r\nCMD:{tvalues.CMD}\r\nCHECKTIME:{tvalues.CHECKTIME}\r\nRECORDS:{tvalues.RECORDS}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }


        #endregion
    }
}
